package cn.uexpo.lhz.controller.admin;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.plus.R;
import cn.uexpo.lhz.common.utils.StringUtil;
import cn.uexpo.lhz.core.http.HttpResult;
import cn.uexpo.lhz.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import cn.uexpo.lhz.biz.EventLocationBiz;
import cn.uexpo.lhz.common.oldBase.BaseController;
import cn.uexpo.lhz.common.utils.JsonData;

/**
 * 项目设置
 */
@RestController
@RequestMapping("/cert/eventLocation")
public class EventLocationController extends BaseController<EventLocation> {

    @Autowired
    private EventLocationBiz eventLocationBiz;

    /**
     * 根据ID删除单个项目位置信息
     * @return
     */
    @GetMapping("/deleteLocationSingle")
    public R deleteLocationSingle(@RequestParam String eventLocationId) {
        eventLocationBiz.deleteByPrimaryKey(Integer.parseInt(eventLocationId));
        return R.ok();
    }

    /**
     * 根据ID更新单个项目位置信息
     *
     * @param eventLocation
     * @return
     */
    @PostMapping("/updateLocationSingle")
    public R updateLocationSingle(@RequestBody EventLocation eventLocation) {
        eventLocationBiz.updateByPrimaryKeySelective(eventLocation);
        return R.ok().put("list", eventLocation);
//		return JsonData.toJsonObject("项目位置信息更新成功", "200", true, eventLocation);
    }

    /**
     * 新增单个项目位置信息
     *
     * @param eventLocation
     * @return
     * @throws Exception
     */
    @PostMapping("/addEventLocationSingle")
    public R addEventLocationSingle(@RequestBody EventLocation eventLocation) throws Exception {
        Date date = new Date();     //获取一个Date对象
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   //创建一个格式化日期对象
        String time = simpleDateFormat.format(date);   //格式化后的时间
        Date times = simpleDateFormat.parse(time); //String-->Date
        eventLocation.setLocationCreatetime(times);
        eventLocation.setUntitled1("0");
        eventLocationBiz.insert(eventLocation);
        return R.ok().put("list", eventLocation);
//		return JsonData.toJsonObject("项目位置新增成功", "200", true, eventLocation);
    }

    /**
     * 根据活动ID查询出对应位置
     *
     * @param eventLocation
     * @return
     */
    @RequestMapping("/findEventLocationAll")
    @ResponseBody
    public Object findEventLocationAll(@RequestBody EventLocation eventLocation) {
        EventLocationExample example = new EventLocationExample();
        EventLocationExample.Criteria criteria = example.createCriteria();
        if (eventLocation.getActivityId() != 0) {
            criteria.andActivityIdEqualTo(eventLocation.getActivityId());
        }
        example.setOrderByClause("location_createtime desc");
        List<EventLocation> list = eventLocationBiz.selectByExample(example);

        JsonData jsonData = new JsonData();
        jsonData.setCode(200);
        jsonData.setData(list);
        return jsonData;
    }

    /**
     * 根据活动ID查询出对应位置  带分页
     * @param eventLocation
     * @return
     */
//	@RequestMapping("/findEventLocationAll2")
//	@ResponseBody
//	public HttpResult findEventLocationAll2(@RequestBody EventLocation eventLocation) {
//		EventLocationExample  example=new EventLocationExample();
//		EventLocationExample.Criteria criteria=example.createCriteria();
//		if(eventLocation.getActivityId()!=0) {
//			criteria.andActivityIdEqualTo(eventLocation.getActivityId());
//		}
//		example.setOrderByClause("location_createtime desc");
//		PageResult result=eventLocationBiz.findPage(eventLocation,example);
//		//JsonData jsonData=new JsonData();
//		//jsonData.setCode(200);
//		//jsonData.setData(result);
//		return HttpResult.ok(result);
//	}


}
